#!pip install folium
import folium
from folium import plugins
from folium.plugins import HeatMap
import requests
import pandas as pd
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
'''
Part 1: Getting the Data
'''
arrest_table = pd.read_csv("https://cmsc320.github.io/files/BPD_Arrests.csv")
arrest_table = arrest_table[pd.notnull(arrest_table["Location 1"])]
arrest_table["lat"], arrest_table["long"] = arrest_table["Location 1"].str.split(",").str
arrest_table["lat"] = arrest_table["lat"].str.replace("(", "").astype(float)
arrest_table["long"] = arrest_table["long"].str.replace(")", "").astype(float)
arrest_table.head()
#Sample randomly from all arrests
arrest_table = (arrest_table.sample(n=15000)).reset_index()
'''
Part 2: Making a map
'''
map_osm = folium.Map(location=[39.29, -76.61], zoom_start=11)
map_osm
'''
Part 3: Combining Parts 1 and 2
'''
map_osm = folium.Map(location=[39.29, -76.61], zoom_start=12)
#This map looks at the narcotics arrests (87, 87O) across all of Baltimore
color_dict = {
'87-':'darkred', # Narcotics arrest
'87O':'red'} # Narcotics (Outside) arrest
for index, row in arrest_table.iterrows():
code = str(row['incidentOffense'])[0:3]
if code == '87-' or code == '87O':
folium.CircleMarker(location=[row['lat'], row['long']], radius = 1.5, popup=row['incidentOffense'], fill=True, color=color_dict[code], fill_opacity=0.8).add_to(map_osm)
map_osm